package com.linghang.demo.controller;

import com.linghang.demo.domain.FootPic;
import com.linghang.demo.req.FootPicSaveReq;
import com.linghang.demo.resp.CommonResp;
import com.linghang.demo.service.FootPicService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

//工作室简介
@RestController
@RequestMapping ("/foot")
public class FootPicController {

    @Resource
    private FileController fileController;

    @Resource
    private FootPicService foot_picService;


    @GetMapping("/list")
    public CommonResp list() {
        CommonResp<List<FootPic>> resp = new CommonResp<>();
        List<FootPic> list = foot_picService.list();
        resp.setContent(list);
        return resp;
    }

//    @GetMapping("/list")
//    public CommonResp list(@Valid FootPicQueryReq req) {
//        CommonResp<PageResp<FootPicQueryResp>> resp = new CommonResp<>();
//        PageResp<FootPicQueryResp> list = foot_picService.list(req);
//        resp.setContent(list);
//        return resp;
//    }

    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable int id){
        CommonResp resp=new CommonResp<>();
        foot_picService.delete(id);

        return resp;
    }

    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody FootPicSaveReq req) {
        CommonResp resp = new CommonResp<>();
        if (!req.getUrl().equals(fileController.getImgPath())){
            req.setUrl(fileController.getImgPath());
        }
        foot_picService.save(req);
        return resp;
    }
}